package com.example.lemis.web.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.lemis.common.JsonResponse;
import com.example.lemis.service.ISensitiveWordsService;
import com.example.lemis.model.domain.SensitiveWords;


/**
 *
 *  前端控制器
 *
 *
 * @author lxp
 * @since 2025-06-24
 * @version v1.0
 */
@RestController
@RequestMapping("/api/sensitiveWords")
public class SensitiveWordsController {

    private final Logger logger = LoggerFactory.getLogger( SensitiveWordsController.class );

    @Autowired
    private ISensitiveWordsService sensitiveWordsService;


    /**
    * 描述：根据Id 查询
    *
    */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public JsonResponse<SensitiveWords> getById(@PathVariable("id") Long id)throws Exception {
        SensitiveWords sensitiveWords = sensitiveWordsService.getById(id);
        return JsonResponse.success(sensitiveWords);
    }

    @GetMapping("/check")
    public JsonResponse<?> checkSensitiveWords(@RequestParam String word) {
        boolean containsSensitiveWords = sensitiveWordsService.containsSensitiveWords(word);
        return JsonResponse.success(containsSensitiveWords);
    }

    @PostMapping("/set")
    public JsonResponse<?> setSensitiveWords(@RequestBody SensitiveWords sensitiveWords) {
        boolean setSensitiveWords = sensitiveWordsService.setSensitiveWords(sensitiveWords);
        return JsonResponse.success(setSensitiveWords);
    }
}

